package cn.itsource.org;

import cn.itsource.App;
import cn.itsource.BaseTest;
import cn.itsource.pet.domain.Pet;
import cn.itsource.pet.domain.PetDetail;
import cn.itsource.pet.mapper.PetDetailMapper;
import cn.itsource.pet.mapper.PetMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.math.BigDecimal;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = App.class)
public class CreatePet extends BaseTest {
    @Autowired
    private PetMapper petMapper;
    @Autowired
    private PetDetailMapper petDetailMapper;
    @Test
    public void test1() throws Exception{
        Pet pet = petMapper.findById(70L);
        PetDetail petDetail = petDetailMapper.findByPetId(pet.getId());

        for(int i = 0;i<100;i++){
            if(i%2==0){
                pet.setId(null);//自增长
                petDetail.setId(null);
                pet.setName("小猪佩奇" + i);
                pet.setState(1);
                pet.setShopId(27L);
                pet.setOffsaletime(null);
                pet.setOnsaletime(null);

                pet.setSaleprice(new BigDecimal(i*10));
                pet.setCostprice(new BigDecimal(i*5));

                petMapper.add(pet);
                petDetail.setPetId(pet.getId());
                petDetailMapper.add(petDetail);
            }else{
                pet.setId(null);//自增长
                petDetail.setId(null);
                pet.setName("野猪乔治" + i);
                pet.setState(0);
                pet.setShopId(27L);
                pet.setOffsaletime(null);
                pet.setOnsaletime(null);
                pet.setSaleprice(new BigDecimal(i*10));
                pet.setCostprice(new BigDecimal(i*5));

                petMapper.add(pet);
                petDetail.setPetId(pet.getId());
                petDetailMapper.add(petDetail);
            }
        }
    }
}
